﻿<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.dto.IMessageDTO"%>
<%@page import="com.sinba.common.system.service.IIMessageService"%>
<%@page import="com.sinba.common.utils.TranType"%>
<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.system.dto.SingleGroupReportStatDTO"%>
<%@page import="java.util.List"%>
<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.system.service.IExtractService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%

if(session.getAttribute("systemUser")==null){
	response.sendRedirect( "login.jsp");
	return;
}
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);


ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
//待处理的提现统计
IExtractService extractService = (IExtractService)ac.getBean("extractService");
Integer waitExtractQuy = extractService.extractCount("待受理");
request.setAttribute("waitExtractQuy",waitExtractQuy);

//未读消息
IIMessageService imessageService = (IIMessageService)ac.getBean("imessageService");
IMessageDTO messageDTO = new IMessageDTO();
messageDTO.setReceiveUser("System");
messageDTO.setStatus("未读");
messageDTO.setMtype("Send");
messageDTO.setLimit(1);
PageDTO pageDTO = imessageService.findPageIMessage(messageDTO, "nr_sord", "imId");
request.setAttribute("NRQuy",pageDTO.getTotalSize());

//今天拔出总数
//充值统计
Double rechargeSum = 0D;
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setSearchType("todaySearch");
trDTO.setDtype("Dynamic");
trDTO.setInOrExp("income");
trDTO.setTransactionTypes(new String[]{TranType.ChongZhi});
List<SingleGroupReportStatDTO> sgrs = transactionRecordService.statAccount(trDTO);
for(SingleGroupReportStatDTO sgr : sgrs){
	if(TranType.ChongZhi.equals(sgr.getGroupField())){
		rechargeSum = rechargeSum+sgr.getAggField();
	}
}
request.setAttribute("rechargeSum",rechargeSum);


//全部拔出总数
Double allRechargeSum = 0D;
TransactionRecordDTO trDTO1 = new TransactionRecordDTO();
trDTO1.setDtype("Dynamic");
trDTO1.setInOrExp("income");
trDTO1.setTransactionTypes(new String[]{TranType.ChongZhi});
List<SingleGroupReportStatDTO> sgrs1 = transactionRecordService.statAccount(trDTO1);
for(SingleGroupReportStatDTO sgr : sgrs1){
	if(TranType.ChongZhi.equals(sgr.getGroupField())){
		allRechargeSum = allRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("allRechargeSum",allRechargeSum);

/* //今天在线充值总数
Double payRechargeSum = 0D;
TransactionRecordDTO trDTO2 = new TransactionRecordDTO();
trDTO2.setSearchType("todaySearch");
trDTO2.setDtype("Recharge");
trDTO2.setInOrExp("income");
trDTO2.setRemark("在线充值");
List<SingleGroupReportStatDTO> sgrs2 = transactionRecordService.statAccount(trDTO2);
for(SingleGroupReportStatDTO sgr : sgrs2){
	if("充值".equals(sgr.getGroupField())){
		payRechargeSum = payRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("payRechargeSum",payRechargeSum);

//全部在线充值总数
Double payAllRechargeSum = 0D;
TransactionRecordDTO trDTO3 = new TransactionRecordDTO();
trDTO3.setDtype("Recharge");
trDTO3.setInOrExp("income");
trDTO3.setRemark("在线充值");
List<SingleGroupReportStatDTO> sgrs3 = transactionRecordService.statAccount(trDTO3);
for(SingleGroupReportStatDTO sgr : sgrs3){
	if("充值".equals(sgr.getGroupField())){
		payAllRechargeSum = payAllRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("payAllRechargeSum",payAllRechargeSum); */



//今天注册会员数
IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
Integer todayRegSum = registerUserService.userCount(null,"TodayRegSum",null);
request.setAttribute("todayRegSum",todayRegSum);
//今天激活会员数
Integer todayActivationSum = registerUserService.userCount(null,"TodayActivationSum",null);
request.setAttribute("todayActivationSum",todayActivationSum);

//奖金发放统计
Double allDynamicSum = 0D;
Double allStaticSum = 0D;
Double allRiFenHong=0D;
Double allSum = 0D;
TransactionRecordDTO trDTO4 = new TransactionRecordDTO();
trDTO4.setTransactionTypes(new String[]{TranType.RiFenHong,TranType.DuiPengJiang,TranType.ZhiTuiJiang,TranType.DaiShuJiang,TranType.BoJieJiang,TranType.FuWuJiang});
trDTO4.setInOrExp("income");
List<SingleGroupReportStatDTO> sgrs4 = transactionRecordService.statAccount(trDTO4);
for(SingleGroupReportStatDTO sgr : sgrs4){
	if(TranType.RiFenHong.equals(sgr.getGroupField())){
		allRiFenHong =  allRiFenHong+sgr.getAggField();
	}else{
		allSum = allSum+sgr.getAggField();
	}
}

//今天动态
Double todayDynamicSum = 0D;
Double todayStaticSum = 0D;
Double todayRiFenHong=0D;
Double todayAllSum = 0D;
trDTO4.setSearchType("todaySearch");
List<SingleGroupReportStatDTO> sgrs5 = transactionRecordService.statAccount(trDTO4);
for(SingleGroupReportStatDTO sgr : sgrs5){
	if(TranType.RiFenHong.equals(sgr.getGroupField())){
		todayRiFenHong = todayRiFenHong +sgr.getAggField();
		
	}else{
		todayAllSum = todayAllSum+ sgr.getAggField();
	}
	
	/* if("Static".equals()){
		todayStaticSum =  todayStaticSum+sgr.getAggField();	
	}else{
		todayDynamicSum = todayDynamicSum+sgr.getAggField();
	} */
}

request.setAttribute("allDynamicSum",allDynamicSum);
request.setAttribute("allStaticSum",allStaticSum);
request.setAttribute("allRiFenHong",allRiFenHong);
request.setAttribute("allSum",allSum);

request.setAttribute("todayDynamicSum",todayDynamicSum);
request.setAttribute("todayStaticSum",todayStaticSum);
request.setAttribute("todayRiFenHong",todayRiFenHong);
request.setAttribute("todayAllSum",todayAllSum);
%>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的首页</title>
<script>
$(function(){
	
});

</script>
</head>
<body>
<div style="padding: 20px; font-size: 18px;">
<hr>
<c:if test="${systemUser.userRole eq 'admin1' or systemUser.userRole eq 'admin2'}">
<b>待处理：</b><br>
<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('提现申请','system/extractMain.jsp')">提现申请(${waitExtractQuy })</a><br><br>

<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('站内留言','system/systemMessage.jsp')">未读消息(${NRQuy })</a><br><br>
<hr>
</c:if>
<b>会员相关统计：</b><br>
今天注册会员数：${todayRegSum }<br>
今天激活会员数：${ todayActivationSum }<br>
<br>
<c:if test="${systemUser.userRole eq 'admin1' or systemUser.userRole eq 'admin2'}">
<hr>
<b>拔币相关统计：</b><br>
今天拔出总数：<fmt:formatNumber value="${rechargeSum}" pattern="#0.0"/><br>
全部拔出总数：<fmt:formatNumber value="${allRechargeSum}" pattern="#0.0"/><br>
<br>
<%-- 今天在线充值总数：<fmt:formatNumber value="${payRechargeSum}" pattern="#0.0000"/><br>
全部在线充值总数：<fmt:formatNumber value="${payAllRechargeSum}" pattern="#0.0000"/><br>
<br> --%>
<hr>

<b>奖金发放统计：</b><br>
今天发放奖金总数：
动态：<fmt:formatNumber value="${todayAllSum*0.7}" pattern="#0.0000"/>+
日分红：<fmt:formatNumber value="${todayRiFenHong}" pattern="#0.0000"/>+
子账户：<fmt:formatNumber value="${todayAllSum*0.3}" pattern="#0.0000"/>=
<fmt:formatNumber value="${(todayAllSum+todayRiFenHong)}" pattern="#0.0000"/>
<br>
全部奖金发放总数：
动态：<fmt:formatNumber value="${allSum*0.7}" pattern="#0.0000"/>+
日分红：<fmt:formatNumber value="${allRiFenHong}" pattern="#0.0000"/>+
子账户：<fmt:formatNumber value="${allSum*0.3}" pattern="#0.0000"/>=
<fmt:formatNumber value="${(allRiFenHong+allSum)}" pattern="#0.0000"/>
<br>
<hr>
<b>奖金占充值总比例：</b><br>
今天：
<c:if test="${rechargeSum>0}">
<fmt:formatNumber value="${(todayAllSum+todayRiFenHong)/rechargeSum*100}" pattern="#0.0000"/>%
</c:if>
<c:if test="${rechargeSum==0}">
	今天充值：0
</c:if>
<br>
<c:if test="${allRechargeSum>0}">
总：<fmt:formatNumber value="${(allRiFenHong+allSum)/allRechargeSum*100}" pattern="#0.0000"/>%
</c:if>
<c:if test="${allRechargeSum==0}">
充值：0
</c:if>
<hr>
</c:if>
</div>
</body>
</html>